package zoo.qboard.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import zoo.qboard.dao.QboardDao;
import zoo.qboard.domain.QboardCommand;

@Controller
public class QboardDeleteController {
	@Autowired
	private QboardDao qboardDao;
	private String formViewName = "qboarddelete";
	
	@ModelAttribute("qboardcommand")
	public QboardCommand formBacking(){
		return new QboardCommand();
	}
	  
	@RequestMapping(value="/main/qboarddelete.do", method=RequestMethod.GET)
	public String form(){
		return formViewName;
	}
	
	@RequestMapping(value="/main/qboarddelete.do", method=RequestMethod.POST)
	public String submit(@ModelAttribute("qboardcommand")QboardCommand qboardCommand,
						 BindingResult result){
		
		if(result.hasErrors()){
			return formViewName;
		}
		qboardDao.deleteQboard(qboardCommand.getBq_num());
		
		return "redirect:/main/qboardlist.do";
	}
}
